<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- vue环境下 -->
  <script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js" type="application/javascript"></script>
</head>
<body>
  <div id="app">
    <!-- 方式 1 通过ref    -->
    <!-- 方式2  通过v-on -->
    <img ref="imgRef" src="http://q6cu3t6jv.bkt.clouddn.com/1063705989926227968?t=1582797590950" @error="onError">
  </div>
</body>
<script>
  //! onerror 错误监听
  let vm = new Vue({
    el: '#app',
    // 在mounted过去dom元素
    mounted() {

      // 注意，这里不能用箭头函数
      this.$refs.imgRef.onerror=function() {
        this.src="https://img01.yzcdn.cn/vant/cat.jpeg"
      }
    },
   methods: {

   onError() {
      this.$refs.imgRef.src="https://img01.yzcdn.cn/vant/cat.jpeg"
    }
   }
  })
</script>
</html>
